<?php
/**
 * 
 * @author huangjian E-mail:870596179@qq.com
 * @version 创建时间：2016年10月25日 上午9:54:24 
 * 类说明
 */
class NoticeAction extends BaseAction{
	/**
	 * @authority 浏览
	 */
	public function index(){
		$this->display('index');
	}
	
	//列表
	public function getAllData(){
		$Model = M($this->getActionName());
		$map = $this->loadSeachCondition();
		$map['flag'] = 1;
		$map['is_all'] = 2;
		$total = $Model->where($map)->count();// 查询满足要求的总记录数
		$page = json_decode($this->pageParam($total));
		$data = $Model->where($map)->limit($page->firstRow,$page->listRows)->order($page->sort)->select();
		$vo = $this->toJosnForGird($data,$page);
		echo json_encode($vo);
	}
	
	/**
	 * 组装条件
	 * @return multitype:multitype:string
	 */
	public function loadSeachCondition(){
		$map = array();
		return $map;
	}
	
	//活动会场列表
	public function getMeetingplaceAllData(){
		$Model = M("Meetingplace");
		$map = $this->loadSeachCondition();
		$map['flag'] = 1;
		$total = $Model->where($map)->count();// 查询满足要求的总记录数
		$page = json_decode($this->pageParam($total));
		$data = $Model->where($map)->limit($page->firstRow,$page->listRows)->order($page->sort)->select();
		$vo = $this->toJosnForGird($data,$page);
		echo json_encode($vo);
	}
	
	public function product(){
		$TypeModel = M("Type");
		$map['reserve'] = 1;
		$map['flag'] = 1;
		$types = $TypeModel->where($map)->field("id,type_name as name")->order("seq asc")->select();
		$this->assign("types",$types);
		$this->display();
	}
	
	//产品列表
	public function getProductAllData(){
		$Model = M("Product");
		$map = $this->loadProductSeachCondition();
		$map['a.flag'] = 1;
		$where = $this->loadSeachCondition();
		$where['flag'] = 1;
		$total = $Model->where($where)->count();// 查询满足要求的总记录数
		$page = json_decode($this->pageParam($total));
		if(!empty($page->sort)){
			$sort = 'a.'.$page->sort;
		}else{
			$sort = $page->sort;
		}
		$data = $Model->alias('a')->join('left join __TYPE__ as b on b.id = a.type_id')->field('a.id,a.name,a.spec,a.desc,a.price,a.is_on,a.seq,a.create_time,b.type_name')->where($map)->limit($page->firstRow,$page->listRows)->order($sort)->select();
		$vo = $this->toJosnForGird($data,$page);
		echo json_encode($vo);
	}
	
	/**
	 * 组装条件
	 * @return multitype:multitype:string
	 */
	public function loadProductSeachCondition(){
		$map = array();
		if(!empty($_GET['name'])){
			$map['name'] = array("like","%".$_GET['name']."%");
		}
		if(!empty($_GET['type_id'])){
			$map['type_id'] = $_GET['type_id'];
		}
		return $map;
	}
	
}